package com.hopes.bizz.risk.control.vo;

import com.hopes.bizz.common.core.util.DateUtils;
import com.hopes.bizz.common.core.util.StringUtils;
import com.hopes.bizz.risk.common.constant.enums.RiskModDictEnum;
import com.hopes.bizz.risk.common.constant.enums.RiskSysDictEnum;
import com.hopes.boss.admin.api.entity.SysDictItem;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.admin.api.resolver.enums.SysDictEnum;
import com.hopes.boss.common.entity.BaseLogicEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/7/19 10:29
 * @Description:
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "风险分析单元VO")
public class RiskUnitVO extends BaseLogicEntity {
    private static final long serialVersionUID = 1L;

    @Schema(description="id")
    private Long id;

    @Schema(description="风险对象标识")
    private Long riskObjectId;

    @Schema(description="风险单元类型")
    private Integer riskUnitType;

    @Schema(description="风险单元名称")
    private String riskName;

    @Schema(description="风险单元编码")
    private String riskCode;

    @Schema(description="责任部门")
    private String deptId;

    @Schema(description="责任岗位")
    private String postId;

    @Schema(description="负责人")
    private String principal;

    @Schema(description="管控层级")
    private String controlLevel;

    @Schema(description="风险点位置")
    private String riskLocation;

    @Schema(description="投用日期")
    private Date serviceDate;

    @Schema(description="潜在隐患情况")
    private String hazardDesc;

    @Schema(description="应急处置措施")
    private String emergencyDesc;

    @Schema(description="是否已辨识")
    private Boolean identifyFlag;

    @Schema(description="辨识方法")
    private String identifyMethod;

    @Schema(description="评估方法")
    private String evaluateMethod;

    @Schema(description="评估日期")
    private Date evaluateDate;

    @Schema(description="复评日期")
    private Date reevaluateDate;

    @Schema(description="评估负责人")
    private Long evaluateUserId;

    @Schema(description="辨识负责人")
    private Long identifyUserId;

    @Schema(description="审核人")
    private Long auditUserId;

    @Schema(description="审核日期")
    private Date auditDate;

    @Schema(description="评估参与人员")
    private String evaluateMember;

    @Schema(description="经度")
    private String longitude;

    @Schema(description="纬度")
    private String latitude;

    @Schema(description="高度")
    private String altitude;

    @Schema(description="范围")
    private String areaScope;

    @Schema(description="二维码")
    private String qrCode;

    @Schema(description="NFC编码")
    private String nfcCode;

    @Schema(description="备注")
    private String remarks;

    @Schema(description="照片")
    private String img;

    @Schema(description="数据是否上报")
    private Boolean reportDataFlag;

    @Schema(description="固有风险等级")
    private Integer riskLevel;

    @Schema(description="固有风险值")
    private Integer riskValue;

    @Schema(description="固有风险描述")
    private String riskDesc;

    @Schema(description="控制后风险值")
    private Integer afterRiskValue;

    @Schema(description="控制后风险等级")
    private Integer afterRiskLevel;

    @Schema(description="控制后风险描述")
    private String afterRiskDesc;

    @Schema(description="机构ID")
    private Long orgId;

    // 合并多少行
    private int rowCount;

    private Integer riskUnitEventNum;

    private Integer riskControlMeasureNum;

    private Long taskCount;

//    private List<RiskUnitEvent> riskUnitEventList;
//
//    public String getColor(){
//        LabelValue labelValue = DicUtil.getLabelValue(DicRiskEnum.RISK_LEVEL, this.getRiskLevel());
//        if (labelValue != null){
//            return labelValue.getExt2();
//        }
//        return null;
//    }

    public String getDeptIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_dept, this.getDeptId());
    }

    public String getPrincipalStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getPrincipal());
    }

    public String getEvaluateUserIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, String.valueOf(this.getEvaluateUserId()));
    }

    public String getIdentifyUserIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, String.valueOf(this.getIdentifyUserId()));
    }

    public String getAuditUserIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, String.valueOf(this.getAuditUserId()));
    }

    public String getEvaluateMemberStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, String.valueOf(this.getEvaluateMember()));
    }

    public String getRiskObjectIdStr() {
        return DictResolver.getItemLabelByValue(RiskModDictEnum.risk_object, this.getRiskObjectId());
    }

    public String getRiskLevelStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_level, this.getRiskLevel());
    }

    public String getAfterRiskLevelStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_level, this.getAfterRiskLevel());
    }
    public SysDictItem getRiskLevelLabelValue() {
        return DictResolver.getItemByValue(RiskSysDictEnum.risk_level, String.valueOf(this.getRiskLevel()));
    }
    public SysDictItem getAfterRiskLevelLabelValue() {
        return DictResolver.getItemByValue(RiskSysDictEnum.risk_level, String.valueOf(this.getAfterRiskLevel()));
    }

    public String getRiskUnitTypeStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_unit_type, this.getRiskUnitType());
    }

    public String getEvaluateMethodStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_evaluate_method, this.getEvaluateMethod());
    }

    public String getIdentifyMethodStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_identify_method, this.getIdentifyMethod());
    }

    public String getControlLevelStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_control_level, this.getControlLevel());
    }

    public String getAreaScopeStr() {
        if (StringUtils.isBlank(this.getAreaScope())) {
            return "未标定";
        } else {
            return "已标定";
        }
    }

    public String getReportDataFlagStr() {
        return DictResolver.getItemLabelByValue(SysDictEnum.yes_no_type, this.getReportDataFlag());
    }

    public String getIdentifyFlagStr() {
        return DictResolver.getItemLabelByValue(SysDictEnum.yes_no_type, this.getIdentifyFlag());
    }

    public String getServiceDateStr() {
        return DateUtils.limitDay(this.serviceDate);
    }

    public String getEvaluateDateStr() {
        return DateUtils.limitDay(this.evaluateDate);
    }

    public String getReevaluateDateStr() {
        return DateUtils.limitDay(this.reevaluateDate);
    }

    public String getAuditDateStr() {
        return DateUtils.limitDay(this.auditDate);
    }

    public List<Long> getDeptIdList() {
        List<Long> deptList = new ArrayList<>();
        for (String s : this.deptId.split(StringUtils.COMMA)) {
            deptList.add(Long.parseLong(s));
        }
        return deptList;
    }

    public List<Long> getPrincipalIdList() {
        List<Long> list = new ArrayList<>();
        for (String s : this.principal.split(StringUtils.COMMA)) {
            list.add(Long.parseLong(s));
        }
        return list;
    }
}
